package com.xuan.xwaterfall.component;

import java.util.List;

import android.app.ActivityManager;
import android.content.Context;
import android.graphics.Bitmap;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.xuan.xwaterfall.R;
import com.xuan.xwaterfall.XWaterFall;
import com.xuan.xwaterfall.loader.ImageLoader;

public class ImageWaterFall extends XWaterFall {
	
	private String TAG = "ImageWaterFall";
	private Context context;
	private List<String> imgs;
	private LayoutInflater inflater;
	

	public ImageWaterFall(Context context, List<String> imgs) {
		super(context,3,0);//设置waterfall的context、列数、宽度
		// TODO Auto-generated constructor stub
		this.context = context;
		this.inflater = LayoutInflater.from(context);
		this.imgs = imgs;
		
	}

	@Override
	public View getView(int position) {
		// TODO Auto-generated method stub
		View view = inflater.inflate(R.layout.item_my_image, null);
		MyImageView iv = (MyImageView) view.findViewById(R.id.iv);
		iv.setName("美女"+position);
		TextView tv = (TextView) view.findViewById(R.id.tvName);
		tv.setText("美女: " + position);
		return view;
	}

	@Override
	public int getContentChildCount() {
		// TODO Auto-generated method stub
		return imgs.size();
	}

	@Override
	public int getNewChildNum() {
		// TODO Auto-generated method stub
		return 12;
	}

	@Override
	public void onScrollToBottom() {
		// TODO Auto-generated method stub
		notifyDataSetChanged();
	}

	@Override
	public Object getMark(int position) {
		// TODO Auto-generated method stub
		return imgs.get(position);
	}

	@Override
	protected void onRecycleView(int position, View view) {
		// TODO Auto-generated method stub
		MyImageView iv = (MyImageView) view.findViewById(R.id.iv);
		TextView tv = (TextView)view.findViewById(R.id.tvName);
		tv.setBackgroundColor(context.getResources().getColor(R.color.orange));
		String url = imgs.get(position);
		Bitmap bm = ImageLoader.getBitmap(url);
		if (bm != null && !bm.isRecycled())
			bm.recycle();
		iv.setImageBitmap(null);
		ImageLoader.deleteBitmap(url);
		android.view.ViewGroup.LayoutParams params = iv.getLayoutParams();
		params.height = iv.getHeight();
		params.width = iv.getWidth();
		iv.setLayoutParams(params);
		iv.recycle();
	}

	@Override
	protected void onResumeView(int position, View view) {
		// TODO Auto-generated method stub
		TextView tv = (TextView)view.findViewById(R.id.tvName);
		tv.setBackgroundColor(context.getResources().getColor(R.color.green));
		MyImageView iv = (MyImageView) view.findViewById(R.id.iv);
		ImageLoader.loadImg(imgs.get(position), iv);
		iv.resume();
	}

	@Override
	public int getChildHeight(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

}
